package com.wzdigit.wms.wms.controller.tms;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.domain.dtos.api.ApiMessage;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.domain.dto.TmsDispatchResultDto;
import com.wzdigit.wms.wms.service.tms.TmsDispatchResultService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "TMS接口")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class TmsDispatchResultController {

    private static final String   REQUEST_MODEL = "tms";

    @Autowired
    TmsDispatchResultService tmsDispatchResultService;

    @ApiOperation(value = "TMS调度结果接收", notes = "TMS调度结果接收")
    @ApiResponses({@ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class)})
    @PostMapping(value = REQUEST_MODEL + "/dispatch/add")
    public ApiMessage searchAsnHeaderReceive(
            @RequestBody TmsDispatchResultDto dto,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) {
        try {
            return tmsDispatchResultService.add(dto);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return  new ApiMessage(ApiMessage.RESULT_ERROR,"添加失败");
        }
    }

}
